<div class="row-content am-cf">
    <div class="row">
        <div class="am-u-sm-12 am-u-md-12 am-u-lg-12">
            <div class="widget am-cf">
                <form id="my-form" class="am-form tpl-form-line-form" method="post">
                    <div class="widget-body">
                        <fieldset>
                            <div class="widget-head am-cf">
                                <div class="widget-title am-fl">添加优惠券</div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">优惠券名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[name]"
                                           value="<?=$list['name']?>" placeholder="请输入优惠券名称" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">优惠券颜色 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="color" name="data[color]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择优惠券颜色', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php foreach ($coupon_color as $key => $g): ?>
                                            <?php if($list['color'] == $key): ?>
                                                <option value="<?=$key ?>" selected="selected" ><?=$g?></option>
                                            <?php else:?>
                                                <option value="<?=$key ?>" ><?=$g?></option>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">是否为虚拟优惠券 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="color" name="data[lq_type]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择虚拟优惠券类型', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php foreach ($lq_type as $key => $g): ?>
                                            <?php if($list['lq_type'] == $key): ?>
                                                <option value="<?=$key ?>" selected="selected" ><?=$g?></option>
                                            <?php else:?>
                                                <option value="<?=$key ?>" ><?=$g?></option>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label form-require">优惠券类型 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="color" name="data[coupon_type]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择优惠券类型', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php foreach ($coupon_type as $key => $g): ?>
                                            <?php if($list['coupon_type'] == $key): ?>
                                                <option value="<?=$key ?>" selected="selected" ><?=$g?></option>
                                            <?php else:?>
                                                <option value="<?=$key ?>" ><?=$g?></option>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">满减券-减免金额 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[reduce_price]"
                                           value="<?=$list['reduce_price']?>" placeholder="满减券-减免金额" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">折扣券-折扣率 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" maxlength="3" class="tpl-form-input" name="data[discount]"
                                           value="<?=$list['discount']?>" placeholder="折扣券-折扣率" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">最低消费金额 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[min_price]"
                                           value="<?=$list['min_price']?>"  placeholder="折扣券-折扣率" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">到期类型 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="province" name="data[expire_type]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择到期类型', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php foreach ($expire_type as $key => $g): ?>
                                            <?php if($list['expire_type'] == $key): ?>
                                                <option value="<?=$key ?>" selected="selected" ><?=$g?></option>
                                            <?php else:?>
                                                <option value="<?=$key ?>" ><?=$g?></option>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">领取后生效-有效天数 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" class="tpl-form-input" name="data[expire_day]"
                                           value="<?=$list['expire_day']?>"  placeholder="有效天数" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">开始时间 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="datetime-local" class="tpl-form-input" name="data[start_time]"
                                           value="<?=$list['start_time']?>"  placeholder="开始时间" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">结束时间 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="datetime-local" class="tpl-form-input" name="data[end_time]"
                                           value="<?=$list['end_time']?>"  placeholder="结束时间" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">适用范围 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="province" name="data[apply_range]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择适用范围', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php foreach ($apply_range as $key => $g): ?>
                                            <?php if($list['apply_range'] == $key): ?>
                                                <option value="<?=$key ?>" selected="selected" ><?=$g?></option>
                                            <?php else:?>
                                                <option value="<?=$key ?>" ><?=$g?></option>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">发放总数量(-1为不限制) </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" class="tpl-form-input" id="lat" name="data[total_num]"
                                           value="<?=$list['total_num']?>" placeholder="发放总数量" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">已领取数量 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[receive_num]"
                                           value="<?=$list['receive_num']?>" placeholder="已领取数量" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">排序 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="number" class="tpl-form-input" name="data[sort]"
                                           value="<?=$list['sort']?>" placeholder="排序方式" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">小程序id </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[wxapp_id]"
                                           value="<?=$list['wxapp_id']?>" placeholder="小程序id" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">商铺名称 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="province" name="data[shop_id]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择商铺', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php foreach ($shopData as $g): ?>
                                            <?php if($list['shop_id'] == $g['id']): ?>
                                                <option value="<?=$g['id'] ?>" selected="selected"><?=$g['name']?></option>
                                            <?php else:?>
                                                <option value="<?=$g['id'] ?>" ><?=$g['name']?></option>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">承担类型 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <select id="province" name="data[bear_type]" style="float: right;"
                                            data-am-selected="{searchBox: 1, btnSize: 'sm',
                                             placeholder:'请选择承担类型', maxHeight: 400}">
                                        <option value=""></option>
                                        <?php foreach ($bear_type as $key => $g): ?>
                                            <?php if($list['bear_type'] == $key): ?>
                                                <option value="<?=$key ?>" selected="selected" ><?=$g?></option>
                                            <?php else:?>
                                                <option value="<?=$key ?>" ><?=$g?></option>
                                            <?php endif; ?>
                                        <?php endforeach; ?>
                                    </select>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <label class="am-u-sm-3 am-u-lg-2 am-form-label">商家承担比例 </label>
                                <div class="am-u-sm-9 am-u-end">
                                    <input type="text" class="tpl-form-input" name="data[shop_bear_rate]"
                                           value="<?=$list['shop_bear_rate']?>" placeholder="商家承担比例" required>
                                </div>
                            </div>
                            <div class="am-form-group">
                                <div class="am-u-sm-9 am-u-sm-push-3 am-margin-top-lg">
                                    <input type="hidden" name="data[coupon_id]" value="<?=$list['coupon_id']?>">
                                    <input type="submit" class="j-submit am-btn am-btn-secondary" name="subd" value="提交" />
                                </div>
                            </div>
                        </fieldset>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script>
    $(function () {

        /**
         * 表单验证提交
         * @type {*}
         */
        $('#my-form').superForm();

    });

    function regionSelect(obj,type){
        var val = $(obj).val();
        if(val >0){
            $("#lng").val($(obj).find("option:selected").attr("lng"));
            $("#lat").val($(obj).find("option:selected").attr("lat"));
            if(type == "city"){
                $("#city").html("");
                $("#district").html("");
            }
            var url = "<?=url('ajaxRegion')?>";
            $.ajax({
                url:url,
                data: {id:val},
                success:function (data) {
                    delProvince(data.data,type)
                }
            });
        }

    }

    function delProvince(data,type) {
        if(data && type){
            $("#"+type).html("");
            var htmlVal = "<option value=''></option>";
            $.each(data,function (i,val) {
                htmlVal += "<option value='"+val.id+"' lng='"+val.lng+"' lat='"+val.lat+"'>"+val.name+"</option>"
            });
            $("#"+type).html(htmlVal);
        }
    }
</script>
